package com.lak.nagivation.controller;

import com.lak.nagivation.bean.CalResult;
import com.lak.nagivation.bean.TXTResult;
import com.lak.nagivation.bean.User;
import com.lak.nagivation.cal.RoutePlan;
import com.lak.nagivation.cal.TXT2Road;
import com.lak.nagivation.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;

@CrossOrigin

@Api(value="Road Controller",tags={"路径计算接口"})
@RestController
@RequestMapping("user")
public class RoadCtrl {


    @PostMapping("/getRoute")
    @ApiOperation("返回路径规划结果")
    public ResponseEntity<Response> postRoute(@RequestParam("origin") String origin, @RequestParam("destination") String destination) {

        try {
            CalResult re=RoutePlan.getRoad(origin,destination);
            return ResponseEntity.ok().body(new Response("200", "查询成功！",re));
        }catch (Exception e){
            return ResponseEntity.ok().body(new Response("201", "查询失败！"));
        }
    }

    @PostMapping("/getGeocode")
    @ApiOperation("返回地理编码")
    @ResponseBody
    public ResponseEntity<Response> postGeocode(@RequestParam("text") String txt) throws UnsupportedEncodingException{
        try {
            TXTResult re=TXT2Road.getGeocode(txt);
            return ResponseEntity.ok().body(new Response("200", "查询成功！",re));
        }catch (Exception e){
            return ResponseEntity.ok().body(new Response("201", "查询失败！"));
        }
    }


    @PostMapping("/getPoint")
    @ResponseBody
    public CalResult postPoint(@RequestParam("origin") String origin, @RequestParam("destination") String destination) {
        return RoutePlan.getRoad(origin,destination);
    }

//    @PostMapping("/getGeocode")
//    @ResponseBody
//    public TXTResult postGeocode(@RequestParam("text") String txt) throws UnsupportedEncodingException {
//        return TXT2Road.getGeocode(txt);
//    }
}

